import java.util.Arrays;

public class project {
    /**
     *
     */
    public int findUnsortedSubarray(int[] nums) {
        int len=nums.length;
        for(int i=0;i<len-1;i++){
            if(nums[i]>nums[i+1]){
                break;
            }
            if(i==len-2){
                return 0;
            }
        }
        int[] arr=Arrays.copyOf(nums,len);
        Arrays.sort(arr);
        int left=0;
        while (left<len&&nums[left]==arr[left]){
            left++;
        }
        int right=len-1;
        while (right>0&&nums[right]==arr[right]){
            right--;
        }
        return right-left+1;
    }




















    public int findMin(int[] nums) {
        int len=nums.length;
        if(nums[0]<nums[len-1]){
            return nums[0];
        }
        int left=0;
        int right=len-1;
        while (left<right){
            int mid=left+(right-left)/2;
            if(nums[mid]<nums[right]){
                right=mid;
            }else if(nums[mid]>nums[right]){
                left=mid+1;
            }else{
                right--;
            }
        }
        return nums[left];
    }














    public int minDeletionSize(String[] strs) {
        int ret=0;
        int row=strs.length;
        int col=strs[0].length();
        for(int i=0;i<col;i++){
            for(int j=0;j<row-1;j++){
                if(strs[j].charAt(i)>strs[j+1].charAt(i)){
                    ret++;
                    break;
                }
            }
        }
        return  ret;
    }
}
